package com.baolai.service.impl;

import com.baolai.entity.Shelf;
import com.baolai.mapper.ShelfMapper;
import com.baolai.service.ShelfService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class ShelfServiceImpl extends ServiceImpl<ShelfMapper, Shelf> implements ShelfService {
    @Override
    public Shelf getShelf(Integer id) {
        return this.getById(id);
    }

    @Override
    public boolean addShelf(Shelf shelf) {
        return this.save(shelf);
    }

    @Override
    public IPage<Shelf> listShelf(Integer current, Integer size) {
        IPage<Shelf> page = new Page<>(current,size);
        return this.page(page);
    }

    @Override
    public boolean updateShelf(Shelf shelf) {
        UpdateWrapper<Shelf> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",shelf.getId());
        return this.update(shelf,updateWrapper);
    }
}
